<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
use Common\Model\AdModel;
use Think\Controller;

class AdController extends  CommonController{


	public function index(){
		$model = new AdModel();
		$data = $model->getList();
		$url = U("admin/ad/index");
		$page = PageShow($data['count'],$url);
		$this->assign('data',$data)->assign('page',$page);

		$this->display();
	}

	public function add(){
		$model = new AdModel();
		if(IS_POST){
			if(!$model->create()){
				$this->error($model->getError());
			}
			$this->success('添加成功',U('admin/ad/index'));
		}
		$this->display();
	}

	public function edit($id){
		$model = new AdModel();
		$ad = $model->getAdById($id);
		if(IS_POST){
			if(!$model->create(false)){
				$this->error($model->getError());
			}
			$this->success('添加成功',U('admin/ad/index'));
		}
		$this->assign('data',$ad);
		$this->display();
	}

	public function del(){
		$id = I('id',0,'int');
		if($id){
			$model = new AdModel();
			$res =$model->delete($id);
			if($res){
				$this->success('删除成功');
			}
		}
		$this->error('删除失败');
	}

}
